<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>商务会员信息列表</title>

</head>
<body>
	<div id="wrap">
		<h1>商务会员管理</h1>
		<div class="search">
			用户名：<input type="text" id="username"> <input id="btnfind"
				type="button" value="查找">
		</div>
		<div class="list">
			<table id="memberList" border="1" width="700px">
				<tr>
					<th>序号</th>
					<th>用户名</th>
					<th>用户类型</th>
					<th>用户状态</th>
					<th>最后修改时间</th>
				</tr>
			</table>
			<div class="pagination">
				<a href="#" id="firstPage">首页</a> | <a href="#" id="prevPage">上一页</a> | <a href="#" id="nextPage">下一页</a>
				| <a href="#" id="lastPage">尾页</a> 第 <span id="showPageNum">1</span> 页/共 <span id="showTotalPage">2</span> 页 (<span id="showTotalCount">7</span>条)
			</div>
		</div>
	</div>

	<!-- 引入jquery.js -->
	<script type="text/javascript" src="static/scripts/jquery.js"></script>

	<script type="text/javascript">
		var totalPage = 0;
		var totalCount = 0;
		var pageNumber = 1; //页码
		
		function search(data){
			$.getJSON("user/search",data,function(result){
				totalPage = result.totalPage;
				totalCount = result.totalCount;
				$("#showPageNum").html(pageNumber);
				$("#showTotalPage").html(totalPage);
				$("#showTotalCount").html(totalCount);
				//alert("totalPage--->" + totalPage);
				$("#memberList tr:not(:first)").remove();
				var html = "";
				$.each(result.rows,function(i,member){
					html += "<tr>";
					html += "<td>"+member.id+"</td>";
					html += "<td>"+member.name+"</td>";
					html += "<td>"+member.userType.name+"</td>";
					html += "<td>"+ (member.status == 1 ? "正常" : "冻结") +"</td>";
					html += "<td>"+member.lastModifyTime+"</td>";
					html += "</tr>";
				});
				$("#memberList tr:first").after(html);
			});
		}
		
		//页面加载完成时，执行
		$(function(){
			search({});
			$("#btnfind").click(function(){
				var formdata = 
				{
					"userName" : $("#username").val(),
					"pageNo" : 1,
					"pageSize" : 5
				};
				search(formdata);
			});
			//alert(totalPage);
			//翻页
			
			//首页
			$("#firstPage").click(function(){
				pageNumber = 1;
				var formdata = 
				{
					"userName" : $("#username").val(),
					"pageNo" : pageNumber,
					"pageSize" : 5
				};
				search(formdata);
			});
			
			//上一页
			$("#prevPage").click(function(){
				if(pageNumber > 1){
					pageNumber = pageNumber-1;
				}
				else{
					pageNumber = 1;
				}
				
				var formdata = 
				{
					"userName" : $("#username").val(),
					"pageNo" : pageNumber,
					"pageSize" : 5
				};
				search(formdata);
			});
			
			//下一页
			$("#nextPage").click(function(){
				if(pageNumber < totalPage){
					pageNumber = pageNumber+1;
				}
				else{
					pageNumber = totalPage;
				}
				
				var formdata = 
				{
					"userName" : $("#username").val(),
					"pageNo" : pageNumber,
					"pageSize" : 5
				};
				search(formdata);
			});
			//最后一页
			$("#lastPage").click(function(){
				pageNumber = totalPage;
				var formdata = 
				{
					"userName" : $("#username").val(),
					"pageNo" : pageNumber,
					"pageSize" : 5
				};
				search(formdata);
			});
			
			//文本改变事件
			$("#username").change(function(){
				pageNumber = 1;
				var formdata = 
				{
					"userName" : $("#username").val(),
					"pageNo" : pageNumber,
					"pageSize" : 5
				};
				search(formdata);
			});
		});
	
	</script>


</body>
</html>